package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pojo.Vehicle;
import com.example.mapper.VehicleMapper;
import com.example.service.IVehicleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vo.ResultVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jayway.jsonpath.internal.Utils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 车辆信息表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-05-06
 */
@Service
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> implements IVehicleService {

    @Override
    public PageInfo<Vehicle> getVehiclePageInfo(String brand, Integer type,Integer pageNum, Integer pageSize,Integer deleted) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<Vehicle> wrapper= new QueryWrapper<>();
        wrapper.like(!Utils.isEmpty(brand),"brand",brand);
        wrapper.eq(type!=null,"type",type);

        List<Vehicle> list= baseMapper.selectList(wrapper.orderByDesc("id"));
        return new PageInfo<>(list);

    }

    @Override
    public ResultVo insertVehicle(Vehicle vehicle) {
        int i = baseMapper.insert(vehicle);
        return i > 0 ? ResultVo.success("新增车辆成功") : ResultVo.error("新增车辆失败");
    }

    @Override
    public ResultVo selectCarNmae() {
        List<Vehicle> list= baseMapper.selectCarNmae();
        return ResultVo.response(list);
    }
}
